<?php
namespace Admin\Controller;
use Common\Controller\AuthController;
class ManageController extends AuthController {
    public function index(){
        $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>[ 您现在访问的是Admin模块的Index控制器 ]</div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }
  
    public function showManulist(){
        $this->display();
    }
    // 菜单列表数据
    public function manulistdata(){
        $Menu=M('admin_nav');    
        $menulists=$Menu->order('id asc,ordernumber asc')->select();
        $newList=array();
        for($i=0;$i<count($menulists);$i++){
            if($menulists[$i]['pid']==0){
                $newList[]=$menulists[$i];
                $pid=$menulists[$i]['id'];
                for($j=0;$j<count($menulists);$j++){
                    if($menulists[$j]['pid']==$pid){
                        $menulists[$j]['_parentId']=$pid;
                        $newList[]=$menulists[$j];
                    }
               
             }
            }
           
        }
        
        $total=$Menu->count();
        if ($total==0){
            $json='{"total":'.$total.',"rows":[]}';
            echo $json;
        }else{
            $json='{"total":'.$total.',"rows":'.json_encode($newList).'}';//重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
            echo $json;
        }
    }
/**
 * [添加菜单]
 * @return [text] [description]
 */
    public function addmeun(){
        $nav = M("admin_nav");
        $nav -> create(); //收集post表单数据
        $result = $nav -> add();
        if($result){
             
             echo '新建菜单成功！';
        }
    }
/**
 * [删除菜单]
 * @return [json] [description]
 */
public function delmenu(){
    $nav = M("admin_nav");
    $map['id']= $_POST['id'];  
    $data=$nav->where($map)->find();

    $mapa['pid']=$_POST['id'];
    $childnum=$nav->where($mapa)->count();

    if($childnum>0){
        $data['status']=0;
        $data['data']="不能删除包含子菜单的菜单！";
        echo json_encode($data);
    }else{
       $r=$nav->where($map)->delete(); 

        if($r){
            $data['status']=1;
            $data['data']="删除子菜单成功！";
            echo json_encode($data);
        }
    }
      
}
/**
 * [显示主菜单，填充commbox]
 * @return [json] [description]
 */
public function showfmenu(){
    $nav = M("admin_nav");
    $map['pid']=0;
    $data=$nav->where($map)->field('id as value,text as text')->select();
    echo json_encode($data);
}
/**
 * [修改菜单]
 * @return [json] [description]
 */
public function modifymenu(){


    $nav = M("admin_nav");


     $id=$_POST['id'];
        
       if($_POST['id']){
           $map['id'] = $id;
            $data['pid']=$_POST['pid'];
           $data['text']=$_POST['text'];
           $data['url']=$_POST['url'];
           $data['icon']=$_POST['icon'];
           $data['ordernumber']=$_POST['ordernumber'];
 
           $result = $nav->where($map)->save($data);
           if(false !== $result)

           echo '修改菜单成功！';
           else
            echo '修改菜单失败！';       
           }       
       else
       {
            echo '没有选择菜单！'; 
       }
     
}
 public function iconlist(){
        $data= array
          (
array("text"=>'add',"iconCls"=>'icon-standard-application-add',"value"=>'icon-standard-application-add'),
array("text"=>'cascade',"iconCls"=>'icon-standard-application-cascade',"value"=>'icon-standard-application-cascade'),
array("text"=>'delete',"iconCls"=>'icon-standard-application-delete',"value"=>'icon-standard-application-delete'),
array("text"=>'double',"iconCls"=>'icon-standard-application-double',"value"=>'icon-standard-application-double'),
array("text"=>'edit',"iconCls"=>'icon-standard-application-edit',"value"=>'icon-standard-application-edit'),
array("text"=>'error',"iconCls"=>'icon-standard-application-error',"value"=>'icon-standard-application-error'),
array("text"=>'form-add',"iconCls"=>'icon-standard-application-form-add',"value"=>'icon-standard-application-form-add'),
array("text"=>'form-delete',"iconCls"=>'icon-standard-application-form-delete',"value"=>'icon-standard-application-form-delete'),
array("text"=>'form-edit',"iconCls"=>'icon-standard-application-form-edit',"value"=>'icon-standard-application-form-edit'),
array("text"=>'form-magnify',"iconCls"=>'icon-standard-application-form-magnify',"value"=>'icon-standard-application-form-magnify'),
array("text"=>'form',"iconCls"=>'icon-standard-application-form',"value"=>'icon-standard-application-form'),
array("text"=>'get',"iconCls"=>'icon-standard-application-get',"value"=>'icon-standard-application-get'),
array("text"=>'go',"iconCls"=>'icon-standard-application-go',"value"=>'icon-standard-application-go'),
array("text"=>'home',"iconCls"=>'icon-standard-application-home',"value"=>'icon-standard-application-home'),
array("text"=>'key',"iconCls"=>'icon-standard-application-key',"value"=>'icon-standard-application-key'),
array("text"=>'lightning',"iconCls"=>'icon-standard-application-lightning',"value"=>'icon-standard-application-lightning'),
array("text"=>'link',"iconCls"=>'icon-standard-application-link',"value"=>'icon-standard-application-link'),
array("text"=>'osx-terminal',"iconCls"=>'icon-standard-application-osx-terminal',"value"=>'icon-standard-application-osx-terminal'),
array("text"=>'osx',"iconCls"=>'icon-standard-application-osx',"value"=>'icon-standard-application-osx'),
array("text"=>'put',"iconCls"=>'icon-standard-application-put',"value"=>'icon-standard-application-put'),
array("text"=>'side-boxes',"iconCls"=>'icon-standard-application-side-boxes',"value"=>'icon-standard-application-side-boxes'),
array("text"=>'side-contract',"iconCls"=>'icon-standard-application-side-contract',"value"=>'icon-standard-application-side-contract'),
array("text"=>'side-expand',"iconCls"=>'icon-standard-application-side-expand',"value"=>'icon-standard-application-side-expand'),
array("text"=>'side-list',"iconCls"=>'icon-standard-application-side-list',"value"=>'icon-standard-application-side-list'),
array("text"=>'side-tree',"iconCls"=>'icon-standard-application-side-tree',"value"=>'icon-standard-application-side-tree'),
array("text"=>'split',"iconCls"=>'icon-standard-application-split',"value"=>'icon-standard-application-split'),
array("text"=>'tile-horizontal',"iconCls"=>'icon-standard-application-tile-horizontal',"value"=>'icon-standard-application-tile-horizontal'),
array("text"=>'tile-vertical',"iconCls"=>'icon-standard-application-tile-vertical',"value"=>'icon-standard-application-tile-vertical'),
array("text"=>'view-columns',"iconCls"=>'icon-standard-application-view-columns',"value"=>'icon-standard-application-view-columns'),
array("text"=>'view-detail',"iconCls"=>'icon-standard-application-view-detail',"value"=>'icon-standard-application-view-detail'),
array("text"=>'view-gallery',"iconCls"=>'icon-standard-application-view-gallery',"value"=>'icon-standard-application-view-gallery'),
array("text"=>'view-icons',"iconCls"=>'icon-standard-application-view-icons',"value"=>'icon-standard-application-view-icons'),
array("text"=>'view-list',"iconCls"=>'icon-standard-application-view-list',"value"=>'icon-standard-application-view-list'),
array("text"=>'view-tile',"iconCls"=>'icon-standard-application-view-tile',"value"=>'icon-standard-application-view-tile'),
array("text"=>'xp-terminal',"iconCls"=>'icon-standard-application-xp-terminal',"value"=>'icon-standard-application-xp-terminal'),
array("text"=>'group',"iconCls"=>'icon-standard-group',"value"=>'icon-standard-group')

          );
echo json_encode($data);
    }  
}